package com.hx.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.enums.BusinessType;
import com.hx.order.domain.Receiver;
import com.hx.order.service.IReceiverService;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.common.core.page.TableDataInfo;

/**
 * 收货地址Controller
 *
 * @author ord
 * @date 2023-05-28
 */
@RestController
@RequestMapping("/receiver")
public class ReceiverController extends BaseController {
    @Autowired
    private IReceiverService receiverService;

    /**
     * 查询收货地址列表
     */
    @PreAuthorize("@ss.hasPermi('order:receiver:list')")
    @GetMapping("/list")
    public TableDataInfo list(Receiver receiver)
    {
        startPage();
        List<Receiver> list = receiverService.selectReceiverList(receiver);
        return getDataTable(list);
    }

    /**
     * 导出收货地址列表
     */
    @PreAuthorize("@ss.hasPermi('order:receiver:export')")
    @Log(title = "收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Receiver receiver)
    {
        List<Receiver> list = receiverService.selectReceiverList(receiver);
        ExcelUtil<Receiver> util = new ExcelUtil<Receiver>(Receiver.class);
        util.exportExcel(response, list, "收货地址数据");
    }

    /**
     * 获取收货地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:receiver:query')")
    @GetMapping(value = "/{receiverId}")
    public AjaxResult getInfo(@PathVariable("receiverId") Long receiverId)
    {
        return success(receiverService.selectReceiverByReceiverId(receiverId));
    }

    /**
     * 新增收货地址
     */
    @PreAuthorize("@ss.hasPermi('order:receiver:add')")
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Receiver receiver)
    {
        return toAjax(receiverService.insertReceiver(receiver));
    }

    /**
     * 修改收货地址
     */
    @PreAuthorize("@ss.hasPermi('order:receiver:edit')")
    @Log(title = "收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Receiver receiver)
    {
        return toAjax(receiverService.updateReceiver(receiver));
    }

    /**
     * 删除收货地址
     */
    @PreAuthorize("@ss.hasPermi('order:receiver:remove')")
    @Log(title = "收货地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receiverIds}")
    public AjaxResult remove(@PathVariable Long[] receiverIds)
    {
        return toAjax(receiverService.deleteReceiverByReceiverIds(receiverIds));
    }
}
